package com.kanshu.mvp_pro.mvp;

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public abstract class FragmentPresenter<D extends IFragmentDelegate> extends Fragment implements IFragmentPresenter<D> {

    private D mViewDelegate;

    public FragmentPresenter() {
        try {
            mViewDelegate = provideDelegateClass().newInstance();
        } catch (java.lang.InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mViewDelegate.create(inflater, container, savedInstanceState);
        return mViewDelegate.getRootView();
    }


    @Override
    public D getViewDelegate() {
        return mViewDelegate;
    }
}
